package com.baibei.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

/**
 * 数字选择
 * Created by ChenRui on 2017/5/9 0009 18:10.
 */
public class BaibeiNumberBar extends LinearLayout implements View.OnClickListener {


    private BaibeiEditText mNumberView;

    public BaibeiNumberBar(Context context) {
        this(context, null);
    }

    public BaibeiNumberBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }


    public BaibeiNumberBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater.from(context).inflate(R.layout.widget_number_bar, this, true);
        mNumberView = (BaibeiEditText) findViewById(R.id.et_number);
        findViewById(R.id.img_increase).setOnClickListener(this);
        findViewById(R.id.img_decrease).setOnClickListener(this);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BaibeiEditText);
        int maxValue = a.getInt(a.getIndex(R.styleable.BaibeiEditText_maxValue), 0);
        mNumberView.setMaxValue(maxValue);
        mNumberView.setIncreaseValue(10);
        a.recycle();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.img_decrease) {
            mNumberView.decrease();
        }
        if (view.getId() == R.id.img_increase) {
            mNumberView.increase();
        }
    }

    public int getValue() {
        return mNumberView.getValue();
    }

}
